package com.bizihang.security.core.validate.code;

import com.bizihang.security.core.properties.SecurityProperties;
import com.bizihang.security.core.validate.code.generator.impl.KaptcheImageCodeGenerator;
import com.bizihang.security.core.validate.code.generator.ValidateCodeGenerator;
import com.bizihang.security.core.validate.code.sms.DefaultSmsCodeSenderImpl;
import com.bizihang.security.core.validate.code.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 毕子航 951755883@qq.com
 * @date 2018/08/18
 */
@Configuration
public class ValidateCodeBeanConfig {

	@Autowired
	SecurityProperties securityProperties;

	@Bean
	@ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
	public ValidateCodeGenerator imageValidateCodeGenerator() {
		KaptcheImageCodeGenerator kaptcheImageCodeGenerator = new KaptcheImageCodeGenerator();
		kaptcheImageCodeGenerator.setSecurityProperties(securityProperties);
		return kaptcheImageCodeGenerator;
	}

	@Bean
	@ConditionalOnMissingBean(name = "smsValidateCodeGenerator")
	public ValidateCodeGenerator smsValidateCodeGenerator() {
		KaptcheImageCodeGenerator kaptcheImageCodeGenerator = new KaptcheImageCodeGenerator();
		kaptcheImageCodeGenerator.setSecurityProperties(securityProperties);
		return kaptcheImageCodeGenerator;
	}

	@Bean
	@ConditionalOnMissingBean(SmsCodeSender.class)
	public SmsCodeSender smsCodeSender() {
		return new DefaultSmsCodeSenderImpl();
	}
}
